package servicerealize;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import mapperdao.IUserMapper;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;
import pojo.UserInfo;
import service.IUserService;
import servicerealize.vo.PersonalInfo;

import javax.annotation.Resource;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Service("userOperations")
public class UserService implements IUserService {

    @Resource(name = "IUserMapper")
    private IUserMapper userOperations;

    @Override
    @Nullable
    public String getPassword(String userName) {
        UserInfo userInfo = new UserInfo();
        userInfo.setUserName(userName);
        List<UserInfo> resultInfo = userOperations.select(userInfo);
        if (resultInfo.isEmpty()) {
            return null;
        } else {
            return resultInfo.get(0).getUserPassword();
        }
    }

    @Override
    public List<PersonalInfo> getAllPersonal() {
        return userOperations.getAllPersonalInfo();
    }

    @Override
    public int getUsersCount(String userName) {
        UserInfo userInfo = new UserInfo();
        userInfo.setUserName(userName);
        return userOperations.selectCount(userInfo);
    }

}
